//
//  EmotIconGroup.swift
//  emotIcon
//
//  Created by 半缘君 on 15/12/15.
//  Copyright © 2015年 banyuanjun.cn. All rights reserved.
//

import UIKit
//import Objc

class EmotIconGroup: NSObject {
    /// 表情组的文件夹的名字
    var id:String?
 /// 显示在toolBar的组名
    var group_name_cn:String?
 /// 表情模型数组
    lazy var emoticons:[Emoticon] = [Emoticon]()
    
    init(dict:[String:AnyObject]) {
        super.init()

        id = dict["id"] as? String
        
        group_name_cn = dict["group_name_cn"] as? String
        

        if let arr = dict["emoticons"] as? [[String:AnyObject]] {
            var index = 0
            for var emot in arr {
                if let png = emot["png"] as? String, dir = id{
                    emot["png"] = dir + "/" + png
                }
               emoticons.append(Emoticon(dict: emot))
                //添加删除按钮
                index++
                if index == 20 {
                    emoticons.append(Emoticon(isRemoved: true))
                    index = 0
                }
            }
        }
        //添加空白按钮
        appendEmptyBtn()
    }
    
    override var description:String {
       return printClass(self.classForCoder)
        
    }
    
    func appendEmptyBtn () {
//        print(emoticons.count)
        let count = emoticons.count % 21
        if  count == 0 && emoticons.count > 0 {
            return
        }
        print(count)
        //添加空白按钮
        for _ in count ..< 20 {
            emoticons.append(Emoticon(isEmpty: true))
        }
        //最后添加一个删除按钮
        emoticons.append(Emoticon(isRemoved: true))
    }
}
